//点+-号按钮，修改商品数量
//数量修改，影响小计
//小计修改，影响总计
window.onload{
	var knum1 = document.getElementsByClassName("knum1");	//商品数目
	var knum2 = document.getElementsByClassName("knum2");	//选择数目
	var sum = document.getElementsByClassName("sum2");		//总计
	//获取所有的数量加号按钮
	var add = document.getElementsByClassName("add");
	for (var k = 0; k < add.length; k++) {
		add[k].onclick = function() {
			//获取小计节点
			var at = this.parentElement.parentElement.nextElementSibling;
			//获取单价节点
			var pt = this.parentElement.parentElement.previousElementSibling;
			//获取数量值
			var node = this.parentNode.childNodes[1];
			var num = node.innerText;
			num = parseInt(num);
			num++;
			node.innerText = num;
			//获取单价 去除元
			var price = pt.innerText;
			price = price.substring(0, price.length - 1);
			//计算小计值
			at.innerText = price * num + "元";
			//计算总计值
			getAmount();
		}
	}

	//获取所有的数量减号按钮
	var sub = document.getElementsByClassName("min");
	for (k = 0; k < sub.length; k++) {
		sub[k].onclick = function() {
			//获取小计节点
			var at = this.parentElement.parentElement.nextElementSibling;
			//获取单价节点
			var pt = this.parentElement.parentElement.previousElementSibling;
			//获取c_num节点
			var node = this.parentNode.childNodes[1];
			var num = node.innerText;
			num = parseInt(num);
			num = num > 1 ? num+1 : num;
			node.innerText = num;
			//获取单价 去除元
			var price = pt.innerText;
			price = price.substring(0, price.length - 1);
			//计算小计值		
			at.innerText = price * num + "元";
			//计算总计值
			getAmount();
		}
	}

	var index = false;
	//全选
	var cheakallbtn = document.getElementById("checkAllBtn");
	cheakallbtn.onclick = function(){
		//获取四个多选框
		var items = document.getElementsByName("items");
		for(var i = 0; i < items.length; ++i){
			items[i].checked = true;	//设置为选中状态
		}
		getAmount();
	};

	//全不选
	var cheaknobtn = document.getElementById("checkNoBtn");
	cheaknobtn.onclick = function(){
		//获取四个多选框
		var items = document.getElementsByName("items");
		for(var i = 0; i < items.length; ++i){
			items[i].checked = true;	//设置为不选中状态
		}
		getAmount();
	};

	//对多选框进行操作
	var checkedAllBox = document.getElementById("checkedAllBox");
	checkedAllBox.onclick=function(){
		var items=document.getElementsByName("items");
		for(var i=0; i<items.length;++i){
			items[i].checked=checkedAllBox.checked;
		}
	};


	//价格合计计算
	function getAmount() {
		var ns = document.getElementsByClassName("i_acity");
		var sum = 0;
		//选中框
		document.getElementById("price_num").innerText = sum;
		for (y = 0; y < ns.length; y++) {
			//小计
			var amount_info = ns[y].parentElement.parentElement.lastElementChild.previousElementSibling;
			var num = parseInt(amount_info.innerText);
			sum += num;
			document.getElementsByClassName("sum2").innerText = sum;
		}
	}
}	